<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>待办任务列表</title>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
  <div id="Application">
    <form @submit.prevent="addTask">
      <span>新建任务</span>
      <input type="text" v-model="taskText" placeholder="请输入任务" />
      <button>添加</button>
    </form>
    <ol>
      <li v-for="(item, index) in todos">
        {{ item }}
        <button @click="remove(index)">删除任务</button>
        <hr>
      </li>
    </ol>
  </div>

  <script>
    const { createApp, ref } = Vue;
    let config = {
      setup() {
        const todos = ref([])
        const taskText = ref('')
        const addTask = () => {
          if (taskText.value.length === 0) {
            alert('请输入任务名称')
            return
          }
          todos.value.push(taskText.value)
          taskText.value = ''
        }
        const remove = (index) => {
          todos.value.splice(index, 1)
        }
        return {todos, addTask, remove, taskText};
      },
    };
    createApp(config).mount("#Application");
  </script>
</body>
</html>